<?php

/**
 * If you are not authorized to modify this file, do NOT touch it.
 * @file common.inc.php
 * @author deltamaster
 * @date 2010-12-1
 * @description The file which should be included by any application based on this framework.
 */

/**
 * The following codes are for security issues.
 */
define('IN_IMBA', true); //Preventing illegal access to framework files.

//Disabling Magic Quotes feature in PHP if magic_quotes_gpc option is set to on in php.ini.
//Magic Quotes is deprecated since PHP 5.3, and it is not recommended to use.
if (get_magic_quotes_gpc())
{
	$process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
	while (list($key, $val) = each($process))
	{
		foreach ($val as $k => $v)
		{
			unset($process[$key][$k]);
			if (is_array($v))
			{
				$process[$key][stripslashes($k)] = $v;
				$process[] = &$process[$key][stripslashes($k)];
			}
			else
			{
				$process[$key][stripslashes($k)] = stripslashes($v);
			}
		}
	}
	unset($process);
}

define('IMBA_LIB', dirname(__file__) . '/'); //Temporarily defined here, for it will be used before reading constants table.
require(IMBA_LIB . 'const.inc.php'); //Loading global constants.
require(IMBA_CONFIG_DIR . 'global.conf.php'); //Loading global initialization configuration.
date_default_timezone_set($imba_timezone);
if (OUTPUT_BUFFER) ob_start();

if (!defined('APP_PATH') || !defined('APP_NAME')) exit('APP_PATH and APP_NAME should be defined before initialization.');

require_once (IMBA_LIB . 'exception/exception.class.php');
require_once (IMBA_LIB . 'log/log.class.php');
require_once (IMBA_LIB . 'app.class.php');
require_once (IMBA_LIB . 'template/template.class.php');
//require_once (IMBA_LIB . 'template/form.class.php');
require_once (IMBA_LIB . 'util/ValidationCode.class.php');

$thisApp = new App(APP_NAME, APP_PATH);

switch (IMBA_DB_TYPE)
{
case DB_NULL:
	require_once (IMBA_LIB . 'database/nodb.class.php');
	$db = new NoDB('');
	break;
case DB_TYPE_MYSQL:
	require_once (IMBA_LIB . 'database/dbmysqli.class.php');
	$db = new DBMysqli(IMBA_CONFIG_DIR . 'db.conf.php');
	break;
default:
	exit('Unknown database type. Modify your configuration file please.');
	break;
}

session_start();
if (IMBA_AUTH_ENABLED)
{
    require_once (IMBA_LIB . 'auth/auth.func.php');
    require_once (IMBA_LIB . 'auth/user.class.php');
    $user = new User();
}
else
{
    $user = array();
}

?>